//
//  ProvTableViewController.m
//  QuickCure
//
//  Created by 源 何 on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "ProvTableViewController.h"
#import "Prov.h"
#import "CityTableViewController.h"

@interface ProvTableViewController ()

@property (nonatomic, strong) NSArray *proList;

@end

@implementation ProvTableViewController

#pragma mark
#pragma mark -- 懒加载
- (NSArray *)proList{
    
    //1. 判断对象是否为nil
    if (_proList == nil) {
        
        //2. 加载数据
        _proList = [Prov provWithPlistFileName:@"province"];
    }
    
    //3. 返回数据
    return _proList;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barTintColor = kThemeColor;
    
    self.title = @"选择当前省份位置";
    [self setUpLeftButtonItem];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"prov"];
}

- (void)setUpLeftButtonItem{
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,50, 50)];
    
    [leftBtn setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
}

/*!
 *  如果想任意跳转，就重写goBack方法
 */
- (void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.proList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"prov" forIndexPath:indexPath];

    Prov *model = self.proList[indexPath.row];
    
    cell.textLabel.text = model.name;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    Prov *model = self.proList[indexPath.row];
    
    CityTableViewController *ct = [[CityTableViewController alloc] init];
    
    ct.cityArray = model.cities;
    
    ct.cityBlock = self.provBlock;
    
    [self.navigationController pushViewController:ct animated:YES];
}



@end
